package com.sigmazero13.MKDummy.models;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;

import com.sigmazero13.MKDummy.R;

public enum MKCharacter {
	ARYTHEA("Arythea", R.drawable.blood_cultist, 2, 0, 0, 1),
	GOLDYX("Goldyx", R.drawable.draconum, 0, 1, 2, 0),
	NOROWAS("Norowas", R.drawable.temple_masters, 0, 0, 1, 2),
	TOVAK("Tovak", R.drawable.order_of_the_ninth_circle, 1, 2, 0, 0),
	WOLFHAWK("Wolfhawk", R.drawable.solonavi, 0, 1, 0, 2),
	KRANG("Krang", R.drawable.chaos_shamans, 2, 0, 1, 0),
	VOLKARE("General Volkare", R.drawable.general_volkare, 0, 0, 0, 0, true);
	
	String name;
	Integer factionImage;
	Map<ManaColor, Integer> crystals;
	boolean special = false;
	
	private MKCharacter(String name, Integer factionImage, int red, int blue, int green, int white, boolean special) {
		this.name = name;
		this.factionImage = factionImage;
		crystals = new HashMap<ManaColor, Integer>();
		crystals.put(ManaColor.RED, red);
		crystals.put(ManaColor.BLUE, blue);
		crystals.put(ManaColor.GREEN, green);
		crystals.put(ManaColor.WHITE, white);
		this.special = special;
	}
	
	private MKCharacter(String name, Integer factionImage, int red, int blue, int green, int white) {
		this(name, factionImage, red, blue, green, white, false);
	}
	
	public String getName() {
		return name;
	}
	
	public Integer getFactionImageResourceId() {
		return factionImage;
	}
	
	public List<ManaColor> getDefaultCrystals() {
		List<ManaColor> defaultCrystals = new ArrayList<ManaColor>();
		for (ManaColor mc : ManaColor.values()) {
			if (!mc.isBasic()) continue;
			for (int i = 0; i < crystals.get(mc); i++) {
				defaultCrystals.add(mc);
			}
		}
		
		return defaultCrystals;
	}
	
	public boolean isSpecial() {
		return special;
	}
	
	public static List<String> getCharacterNames() {
		List<String> characters = new ArrayList<String>();
		for (MKCharacter c : MKCharacter.values()) {
			characters.add(c.getName());
		}
		return characters;
	}
	
	public static MKCharacter findByName(String name) {
		for (MKCharacter c : MKCharacter.values()) {
			if (c.getName().equals(name)) {
				return c;
			}
		}
		
		return null;
	}
	
	public static MKCharacter getRandomCharacter(boolean allowSpecial) {
		MKCharacter randomChar = null;
		
		Random r = new Random();
		while (randomChar == null) {
			int randInt = r.nextInt(MKCharacter.values().length);
			if (allowSpecial || !MKCharacter.values()[randInt].isSpecial()) {
				randomChar = MKCharacter.values()[randInt];
			}
		}
		
		return randomChar;
	}
}
